*** Panel includes all samples
	use "$dta/panel_anonymized", clear	
	drop if sample=="Moderators"
	replace weight = 1 if sample=="Elites"
	capture drop _*
	keep HHID weight z* t H* 
	drop H*0
	foreach var of global Hs{
		rename `var'1 `var'
	}
	

*** Two treatment groups each for citizens and elites - ignoring info + spillover group
	gen group = 1 if zdelib==1
	replace g = 0 if z==0
	replace g = 3 if zelite==0
	replace g = 4 if zelite==1
	drop if g==.

*** Keep only variables used in elite poll
	global Hs = "H11 H12 H13 H14 H15 H21 H22 H23 H24 H25 H26 H31 H32 H33 H34 H35 H36 H37 H38 H41 H42 H43 H44 H45 H46 H51 H52 H53 H61 H62 H63 H64 H65 H66 H67 H68 H69"
	global newHs = "H11 H25 H26 H36 H37 H46 H51 H52"	// H45
	*global newHs = "H51"
	keep weight z* g $newHs

*** Create shorter value labels
	local H11min = "Generate electricity"
	local H11max = "Sell gas"
	local H25min = "Spend"
	local H25max = "Save"
	local H26min = "Borrow"
	local H26max = "Don't borrow"
	local H36min = "Gov't spending"
	local H36max = "Cash transfers"
	local H37min = "Against"
	local H37max = "For"
	local H45min = "Disagree"
	local H45max = "Agree"
	local H46min = "Infrastructure"
	local H46max = "Public services"
	local H51min = "Keep private"
	local H51max = "Publish"
	local H52min = "Gov't decides"
	local H52max = "Int'l oversight"

	local H11title = "\hline \addlinespace Sell gas (1.1)"
	local H25title = "Save for the future (2.5)"
	local H26title = "Don't borrow overseas (2.6)"
	local H36title = "Cash transfers (3.6)"
	local H37title = "Personal savings accounts (3.7)"
	local H45title = "Waste in goverment spending (4.5)"
	local H46title = "Spend on services (not infra.) (4.6)"
	local H51title = "Contract transparency (5.1)"
	local H52title = "International oversight (5.2)"
	
*** Create indices on same scale, centered at zero
	foreach var of global newHs{
		sum `var'
		gen i`var' = (`var' - (r(max)+1)/2)/(r(max)-1)
	}
	
	gen x = .
	gen c = 1
	gen elitesample = zelite!=.
	egen T = rsum(zdelib zelite)
	foreach var of global newHs{
		replace x = 1
		/*Citizen control level*/ 		eststo A: reg i`var' x zdelib, nocons 
		/*Elite control level*/ 		eststo B: reg i`var' x zelite, nocons
		replace x = elitesample
		/*Elite-citizen control gap*/	eststo C: reg i`var' x c if zdelib==0 | zelite==0, nocons

		replace x = T
		/*Citizen treatment effect*/	eststo D: reg i`var' x c if zdelib!=., nocons		
		/*Elite treatment effect*/		eststo E: reg i`var' x c if zelite!=., nocons
		replace x = elitesample*T
		/*Narrowing gap?*/				eststo F: reg i`var' x c elitesample T, nocons

		label variable x "``var'title'"
		
		if "`var'"=="H11"{
		esttab A B C D E F using "$floats/elites.tex", 			///
			f booktabs eqlabels(none) label se(3) b(3)				///
			mtitles("Citizens""Elites""Gap""Citizens""Elites""Gap")	///
			keep(x)	mgroups("Average for control" "Treatment effects", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
			nodep nonotes nolines noobs  			 		///
			starlevels(* 0.10 ** 0.05 *** 0.01) se gaps replace	
		}
		else{
		esttab A B C D E F using "$floats/elites.tex",				///
			f booktabs eqlabels(none) label se(3) b(3)				///
			keep(x)													///
			nodep nonotes nolines noobs nonumbers nomtitles 		///
			starlevels(* 0.10 ** 0.05 *** 0.01) se gaps append		
		}
	}
exit
